﻿using Candy.Infrastructure;
using Candy.Model;
using GalaSoft.MvvmLight;
using System;
using System.ServiceModel.DomainServices.Client;

namespace Candy.ViewModel
{
    public class CandyViewModelBase : ViewModelBase
    {
        protected void HandleDomainError(OperationBase op, string title)
        {
            if (!IsInDesignMode)
                ErrorHandler.HandleDomainError(op, title);
        }

        protected void HandleDomainError(CandyOperationBase op, string title)
        {
            if (!IsInDesignMode)
                ErrorHandler.HandleDomainError(op, title);
        }

        protected void HandleException(Exception ex, string title)
        {
            if (!IsInDesignMode)
                ErrorHandler.HandleBusinessError(ex, title);
        }

        protected void HandleException(Exception ex)
        {
            if (!IsInDesignMode)
                ErrorHandler.Handle(ex);
        }

        protected void ResetError()
        {
            if (!IsInDesignMode)
                ErrorHandler.Reset();
        }

        protected void ReportProgress()
        {
            if (!IsInDesignMode)
                ProgressHandler.ShowProgress(this);
        }

        protected void FinishProgress()
        {
            if (!IsInDesignMode)
                ProgressHandler.HideProgress(this);
        }

        protected void ConfirmAction(Action<bool> callback, string message)
        {
            if (!IsInDesignMode)
                ConfirmationHandler.ConfirmAction(callback, message);
            else
                callback(true);
        }
    }
}
